package com.wakala.employment.fragment.other;

import android.annotation.SuppressLint;
import android.graphics.Typeface;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.cy.tablayoutniubility.FragPageAdapterVp2NoScroll;
import com.cy.tablayoutniubility.TabAdapterNoScroll;
import com.cy.tablayoutniubility.TabLayoutNoScroll;
import com.cy.tablayoutniubility.TabMediatorVp2NoScroll;
import com.cy.tablayoutniubility.TabNoScrollViewHolder;
import com.leaf.library.StatusBarUtil;
import com.wakala.employment.R;
import com.wakala.employment.core.BaseFragment;
import com.wakala.employment.databinding.FragmentVisitRecordBinding;
import com.xuexiang.xpage.annotation.Page;
import com.xuexiang.xpage.enums.CoreAnim;
import com.xuexiang.xui.widget.actionbar.TitleBar;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link VisitRecordFragment#} factory method to
 * create an instance of this fragment.
 */
@Page(anim = CoreAnim.none)
public class VisitRecordFragment extends BaseFragment<FragmentVisitRecordBinding> implements View.OnClickListener {

    private Handler mHandler = new Handler(Looper.getMainLooper());
    private ArrayList<Fragment> mFragments = new ArrayList<>();

    @NonNull
    @Override
    protected FragmentVisitRecordBinding viewBindingInflate(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, boolean attachToRoot) {
        return FragmentVisitRecordBinding.inflate(inflater, container, attachToRoot);
    }

    @SuppressLint("UseCompatLoadingForDrawables")
    @Override
    protected TitleBar initTitle() {
        TitleBar titleBar = super.initTitle();
        titleBar.setTitle("查看记录");
        titleBar.setTitleColor(R.color.black);
        titleBar.setLeftTextColor(R.color.black);
        titleBar.setLeftImageDrawable(getResources().getDrawable(R.drawable.icon_arrow_back));
        titleBar.setBackgroundResource(R.color.xui_config_color_light);//设置标题栏背景
        StatusBarUtil.setDarkMode(requireActivity());
        //设置状态栏背景颜色，如果设置为 Color.TRANSPARENT 将会隐藏状态栏
        requireActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.xui_config_color_light));
        return titleBar;
    }

    @Override
    protected void initViews() {
        ViewPager2 viewPager2 = findViewById(R.id.view_pager);
        viewPager2.setUserInputEnabled(false);
        TabLayoutNoScroll tabLayoutLine = findViewById(R.id.tablayout);

        FragPageAdapterVp2NoScroll<String> fragmentPageAdapter = new FragPageAdapterVp2NoScroll<String>(this) {
            @Override
            public Fragment createFragment(String bean, int position) {
                if(position==0){
                    return new VisitWhoMeRecordFragment();
                    //return new NewsFragment();
                }else if(position==1){
                    return new VisitMeWhoRecordFragment();
                }else {
                    return SimpleKindFragment.getInstance( getList_bean().get(position));
                }

            }

            @Override
            public void bindDataToTab(TabNoScrollViewHolder holder, int position, String bean, boolean isSelected) {
                TextView textView = holder.getView(R.id.tv);
                if (isSelected) {
                    textView.setTextColor(0xffe45540);
                    textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                } else {
                    textView.setTextColor(0xff444444);
                    textView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
                }
                textView.setText(bean);
            }

            @Override
            public int getTabLayoutID(int position, String bean) {
                return  R.layout.item_tab;
            }
        };

        TabAdapterNoScroll<String> tabAdapter = new TabMediatorVp2NoScroll<String>(tabLayoutLine, viewPager2).setAdapter(fragmentPageAdapter);


        List<String> list = new ArrayList<>();
        list.add("谁看过我");
        list.add("我看过谁");
        fragmentPageAdapter.add(list);
        tabAdapter.add(list);
    }

    @Override
    public void onClick(View view) {

    }
}